package com.coocaa.x.uipackage.utils;

import android.net.Uri;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.drawee.view.DraweeView;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;

/**
 * Created by lu on 15-8-15.
 */
public class FrescoUtils {

    public static void resize(DraweeView view, Uri uri, int width, int height, Uri previewUri) {
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                .setResizeOptions(new ResizeOptions(width, height))
                .build();

        AbstractDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
                .setOldController(view.getController())
                .setImageRequest(request);
        if (previewUri != null)
            builder = builder.setLowResImageRequest(ImageRequest.fromUri(previewUri));
        view.setController(builder.build());
    }
}
